home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 001 / pibt40s3.arc / PIBSCRN3.MOD < prev    next >
Text File  |  1987-04-05  |  19KB  |  454 lines

  1. (*----------------------------------------------------------------------*)
  2. (*                Save_Screen --- Save current screen image             *)
  3. (*----------------------------------------------------------------------*)
  4.  
  5. PROCEDURE Save_Partial_Screen( VAR Saved_Screen_Pointer : Saved_Screen_Ptr;
  6.                                    X1                   : INTEGER;
  7.                                    Y1                   : INTEGER;
  8.                                    X2                   : INTEGER;
  9.                                    Y2                   : INTEGER  );
  10.  
  11. (*----------------------------------------------------------------------*)
  12. (*                                                                      *)
  13. (*     Procedure:  Save_Partial_Screen                                  *)
  14. (*                                                                      *)
  15. (*     Purpose:    Saves part of current screen image                   *)
  16. (*                                                                      *)
  17. (*     Calling Sequence:                                                *)
  18. (*                                                                      *)
  19. (*        Save_Partial_Screen( VAR Saved_Screen_Pointer :               *)
  20. (*                                      Saved_Screen_Ptr;               *)
  21. (*                                 X1                   : INTEGER;      *)
  22. (*                                 Y1                   : INTEGER;      *)
  23. (*                                 X2                   : INTEGER;      *)
  24. (*                                 Y2                   : INTEGER  );   *)
  25. (*                                                                      *)
  26. (*           Saved_Screen_Pointer  --- pointer to record receiving      *)
  27. (*                                     screen image, window location,   *)
  28. (*                                     and current cursor location.     *)
  29. (*           (X1,Y1)               --- upper left hand corner of area   *)
  30. (*                                     to be saved.                     *)
  31. (*           (X2,Y2)               --- lower right hand corner of area  *)
  32. (*                                     to be saved.                     *)
  33. (*                                                                      *)
  34. (*     Calls:   Move                                                    *)
  35. (*              Upper_Left                                              *)
  36. (*                                                                      *)
  37. (*     Remarks:                                                         *)
  38. (*                                                                      *)
  39. (*        This version checks for stack overflow.                       *)
  40. (*                                                                      *)
  41. (*        Note that text modes can be handled through the BIOS, but     *)
  42. (*        graphics modes always go directly to screen memory -- a       *)
  43. (*        problem to fix sometime in the future.                        *)
  44. (*                                                                      *)
  45. (*----------------------------------------------------------------------*)
  46.  
  47. VAR
  48.    GetMem_Length: INTEGER;
  49.    Graphics_Mode: BOOLEAN;
  50.    X            : INTEGER;
  51.    Y            : INTEGER;
  52.    SaveX        : INTEGER;
  53.    SaveY        : INTEGER;
  54.    Regs         : RegPack;
  55.    S_Pos        : INTEGER;
  56.    F_Pos        : INTEGER;
  57.    L            : INTEGER;
  58.    SVal         : STRING[10];
  59.    SVal2        : STRING[10];
  60.    Vid_Mode     : INTEGER;
  61.  
  62. BEGIN  (* Save_Partial_Screen *)
  63.                                    (* Figure if graphics mode or text  *)
  64.  
  65.    Vid_Mode      := Current_Video_Mode;
  66.    Graphics_Mode := ( Vid_Mode >= MedRes_GraphMode ) AND
  67.                     ( Vid_Mode <> Mono_TextMode );
  68.    L             := SIZEOF( Saved_Screen_Type ) - SIZEOF( Screen_Type );
  69.  
  70.    IF Graphics_Mode THEN
  71.       BEGIN
  72.          GetMem_Length := Graphics_Screen_Length + L;
  73.          F_Pos         := 1;
  74.       END
  75.    ELSE
  76.       BEGIN
  77.          F_Pos         := ( Y1 - 1 ) * Max_Screen_Col + X1;
  78.          S_Pos         := ( Y2 - 1 ) * Max_Screen_Col + X2;
  79.          GetMem_Length := ( S_Pos - F_Pos + 1 ) * 2 + L;
  80.       END;
  81.                                    (* Overwrite last screen if no room *)
  82.                                    (* This needs to be fixed later     *)
  83.  
  84.    IF Current_Saved_Screen >= Max_Saved_Screen THEN
  85.       Saved_Screen_Pointer := Saved_Screen_List[ Max_Saved_Screen ]
  86.    ELSE
  87.       BEGIN
  88.          Current_Saved_Screen := Current_Saved_Screen + 1;
  89.          GETMEM( Saved_Screen_Pointer , GetMem_Length );
  90.          Saved_Screen_List[ Current_Saved_Screen ] := Saved_Screen_Pointer;
  91.       END;
  92.  
  93.    WITH Saved_Screen_Pointer^ DO
  94.       BEGIN
  95.  
  96.          IF ( NOT Graphics_Mode ) THEN
  97.             BEGIN
  98.  
  99.                Upper_Left( Window_X1, Window_Y1 );
  100.  
  101.                Window_X2     := Lower_Right_Column;
  102.                Window_Y2     := Lower_Right_Row;
  103.  
  104.                Screen_Row    := WhereY;
  105.                Screen_Column := WhereX;
  106.  
  107.                Screen_X1     := X1 - 1;
  108.                Screen_Y1     := Y1 - 1;
  109.  
  110.                Screen_X2     := X2 - 1;
  111.                Screen_Y2     := Y2 - 1;
  112.  
  113.             END
  114.          ELSE
  115.             BEGIN
  116.  
  117.                Window_X1     := 0;
  118.                Window_Y1     := 0;
  119.  
  120.                IF ( Vid_Mode = HiRes_GraphMode ) THEN
  121.                   Window_X2  := 639
  122.                ELSE
  123.                   Window_X2  := 319;
  124.  
  125.                Window_Y2     := 199;
  126.  
  127.                Screen_X1     := 0;
  128.                Screen_Y1     := 0;
  129.  
  130.                Screen_X2     := 639;
  131.                Screen_Y2     := 199;
  132.  
  133.                Screen_Row    := Graphics_YPos;
  134.                Screen_Column := Graphics_XPos;
  135.  
  136.             END;
  137.  
  138.          Screen_Size := GetMem_Length - L;
  139.          If_BIOS     := NOT Write_Screen_Memory;
  140.          Video_Mode  := Vid_Mode;
  141.  
  142.                                    (* Freeze screen for DoubleDos *)
  143.  
  144.          IF ( MultiTasker = DoubleDos ) THEN
  145.             BEGIN
  146.                TurnOffTimeSharing;
  147.                Get_Screen_Address( DesqView_Screen );
  148.             END;
  149.  
  150.          IF Graphics_Mode THEN
  151.             MOVE( DesqView_Screen^.Screen_Image[F_Pos * 2 - 1],
  152.                   Screen_Image[1], Screen_Size )
  153.          ELSE IF Write_Screen_Memory THEN
  154.             IF Wait_For_Retrace THEN
  155.                MoveFromScreen( DesqView_Screen^.Screen_Image[F_Pos * 2 - 1],
  156.                                Screen_Image[1], Screen_Size SHR 1 )
  157.             ELSE
  158.                MOVE( DesqView_Screen^.Screen_Image[F_Pos * 2 - 1],
  159.                      Screen_Image[1], Screen_Size )
  160.          ELSE
  161.             BEGIN                  (* Use BIOS (SLOW!!!) *)
  162.  
  163.                SaveX := WhereX;
  164.                SaveY := WhereY;
  165.                S_Pos := 1;
  166.                                    (* Turn off the cursor *)
  167.                CursorOff;
  168.                                    (* Loop over screen area *)
  169.  
  170.                FOR Y := Y1 TO Y2 DO
  171.                   FOR X := X1 TO X2 DO
  172.                      BEGIN
  173.                         ReadCXY( Screen_Image[S_Pos], X, Y, Screen_Image[S_Pos + 1] );
  174.                         S_Pos := S_Pos + 2;
  175.                      END;
  176.                                    (* Restore previous position *)
  177.  
  178.                GoToXY( SaveX, SaveY );
  179.  
  180.                                    (* Turn on the cursor   *)
  181.                CursorOn;
  182.  
  183.             END;
  184.                                    (* Unfreeze screen in DoubleDos *)
  185.  
  186.          IF ( MultiTasker = DoubleDos ) THEN
  187.             TurnOnTimeSharing;
  188.  
  189.          IF Graphics_Mode THEN
  190.             BEGIN
  191.                TextMode( Text_Mode );
  192.                IF EGA_Installed THEN
  193.                   Set_EGA_Text_Mode( Max_Screen_Line );
  194.                Reset_Global_Colors;
  195.             END;
  196.  
  197.       END;
  198.  
  199. END   (* Save_Partial_Screen *);
  200.  
  201. (*----------------------------------------------------------------------*)
  202. (*              Restore_Screen --- Restore saved screen image           *)
  203. (*----------------------------------------------------------------------*)
  204.  
  205. PROCEDURE Restore_Screen( VAR Saved_Screen_Pointer : Saved_Screen_Ptr );
  206.  
  207. (*----------------------------------------------------------------------*)
  208. (*                                                                      *)
  209. (*     Procedure:  Restore_Screen                                       *)
  210. (*                                                                      *)
  211. (*     Purpose:    Restores previously saved screen image.              *)
  212. (*                                                                      *)
  213. (*     Calling Sequence:                                                *)
  214. (*                                                                      *)
  215. (*        Restore_Screen( VAR Saved_Screen_Pointer: Saved_Screen_Ptr ); *)
  216. (*                                                                      *)
  217. (*           Saved_Screen_Pointer  --- pointer to record with saved     *)
  218. (*                                     screen image, window location,   *)
  219. (*                                     and cursor location.             *)
  220. (*                                                                      *)
  221. (*     Calls:   Window                                                  *)
  222. (*              Move                                                    *)
  223. (*              GoToXY                                                  *)
  224. (*              WriteCXY                                                *)
  225. (*                                                                      *)
  226. (*     Remarks:                                                         *)
  227. (*                                                                      *)
  228. (*        All saved screen pointers from the last saved down to the     *)
  229. (*        argument pointer are popped from the saved screen list.       *)
  230. (*                                                                      *)
  231. (*----------------------------------------------------------------------*)
  232.  
  233. VAR
  234.    X            : BYTE;
  235.    Y            : BYTE;
  236.    I            : INTEGER;
  237.    L            : INTEGER;
  238.    F_Pos        : INTEGER;
  239.    Graphics_Mode: BOOLEAN;
  240.    Regs         : RegPack;
  241.    SVal         : AnyStr;
  242.    Vid_Mode     : INTEGER;
  243.    EGA_On       : BOOLEAN;
  244.  
  245. BEGIN  (* Restore_Screen *)
  246.                                    (* Don't restore screen if pointer  *)
  247.                                    (* is nil                           *)
  248.  
  249.    IF ( Saved_Screen_Pointer = NIL ) THEN EXIT;
  250.  
  251.                                    (* Figure if graphics mode or text  *)
  252.  
  253.    Vid_Mode      := Current_Video_Mode;
  254.    Graphics_Mode := ( Vid_Mode >= MedRes_GraphMode ) AND
  255.                     ( Vid_Mode <> Mono_TextMode );
  256.    L             := SIZEOF( Saved_Screen_Type ) - SIZEOF( Screen_Type );
  257.    EGA_On        := EGA_Installed;
  258.  
  259.    WITH Saved_Screen_Pointer^ DO
  260.       BEGIN
  261.  
  262.          IF ( Video_Mode >= MedRes_GraphMode ) AND
  263.             ( Video_Mode <> Mono_TextMode    ) THEN
  264.             BEGIN  (* Process saved graphics screen *)
  265.  
  266.                IF ( NOT Graphics_Mode ) THEN
  267.                   BEGIN
  268.                                    (* If EGA on, make sure 25 line *)
  269.                                    (* text mode.                   *)
  270.  
  271.                      IF EGA_On THEN
  272.                         Set_EGA_Text_Mode( 25 );
  273.  
  274.                                    (* Request graphics mode *)
  275.                      WITH Regs DO
  276.                         BEGIN
  277.                            Regs.Ah := 0;
  278.                            Regs.Al := Video_Mode;
  279.                            INTR( $10, Regs );
  280.                         END;
  281.                                    (* Set graphics colors          *)
  282.  
  283.                      IF Video_Mode = HiRes_GraphMode THEN
  284.                         Set_Graphics_Colors( EGA_On, Video_Mode,
  285.                                              Graphics_ForeGround_Color,
  286.                                              Graphics_BackGround_Color );
  287.  
  288.                   END;
  289.  
  290.                                    (* Freeze screen for DoubleDos *)
  291.  
  292.                IF ( MultiTasker = DoubleDos ) THEN
  293.                   BEGIN
  294.                      TurnOffTimeSharing;
  295.                      Get_Screen_Address( DesqView_Screen );
  296.                   END;
  297.  
  298.                MOVE( Screen_Image, DesqView_Screen^.Screen_Image,
  299.                      Graphics_Screen_Length );
  300.  
  301.                                    (* Unfreeze screen in DoubleDos *)
  302.  
  303.                IF ( MultiTasker = DoubleDos ) THEN
  304.                   TurnOnTimeSharing;
  305.  
  306.                GraphWindow( Window_X1, Window_Y1, Window_X2, Window_Y2 );
  307.  
  308.                Graphics_XPos := Screen_Column;
  309.                Graphics_YPos := Screen_Row;
  310.  
  311.             END    (* Process saved graphics screen *)
  312.          ELSE
  313.             BEGIN   (* Process saved text screen *)
  314.  
  315.                IF Graphics_Mode THEN
  316.                   BEGIN
  317.                      TextMode( Text_Mode );
  318.                      IF EGA_On THEN
  319.                         Set_EGA_Text_Mode( Max_Screen_Line );
  320.                      Reset_Global_Colors;
  321.                   END;
  322.  
  323.                IF ( Write_Screen_Memory AND ( NOT IF_Bios ) ) THEN
  324.                   BEGIN
  325.                                    (* Freeze screen for DoubleDos *)
  326.  
  327.                      IF ( MultiTasker = DoubleDos ) THEN
  328.                         BEGIN
  329.                            TurnOffTimeSharing;
  330.                            Get_Screen_Address( DesqView_Screen );
  331.                         END;
  332.                                    (* Restore screen image *)
  333.  
  334.                      F_Pos := ( Screen_Y1 * Max_Screen_Col + Screen_X1 ) * 2 + 1;
  335.  
  336.                      IF Wait_For_Retrace THEN
  337.                         MoveToScreen( Screen_Image[1],
  338.                                       DesqView_Screen^.Screen_Image[F_Pos],
  339.                                       Screen_Size SHR 1 )
  340.                      ELSE
  341.                         MOVE( Screen_Image[1],
  342.                               DesqView_Screen^.Screen_Image[F_Pos],
  343.                               Screen_Size );
  344.  
  345.                                    (* Unfreeze screen in DoubleDos *)
  346.  
  347.                      IF ( MultiTasker = DoubleDos ) THEN
  348.                          TurnOnTimeSharing
  349.  
  350.                                    (* Synchronize screen for TopView *)
  351.  
  352.                      ELSE IF ( MultiTasker = TopView ) THEN
  353.                          Sync_Screen( F_Pos , Screen_Size );
  354.  
  355.                   END
  356.                ELSE
  357.                   BEGIN
  358.                                    (* Turn off the cursor   *)
  359.                      CursorOff;
  360.  
  361.                      I := 1;
  362.                                    (* Loop over screen area *)
  363.  
  364.                      FOR Y := Screen_Y1 TO Screen_Y2 DO
  365.                         FOR X := Screen_X1 TO Screen_X2 DO
  366.                            BEGIN
  367.                               WriteCXY( CHR(Screen_Image[I]), X + 1, Y + 1,
  368.                                         Screen_Image[I+1] );
  369.                               I := I + 2;
  370.                            END;
  371.                                    (* Turn on the cursor *)
  372.                      CursorOn;
  373.  
  374.                   END;
  375.  
  376.                                    (* Ensure proper screen length *)
  377.  
  378.                Set_Screen_Size( Window_Y2 , Window_X2 );
  379.  
  380.                Window( Window_X1, Window_Y1, Window_X2, Window_Y2 );
  381.                GoToXY( Screen_Column, Screen_Row );
  382.  
  383.             END    (* Process saved text screen *);
  384.  
  385.       END;
  386.  
  387.    WHILE( Saved_Screen_List[ Current_Saved_Screen ] <> Saved_Screen_Pointer ) DO
  388.       BEGIN
  389.          FREEMEM( Saved_Screen_List[ Current_Saved_Screen ] ,
  390.                   Saved_Screen_List[ Current_Saved_Screen ]^.Screen_Size + L );
  391.          Saved_Screen_List[ Current_Saved_Screen ] := NIL;
  392.          Current_Saved_Screen := Current_Saved_Screen - 1;
  393.       END;
  394.  
  395.    IF Current_Saved_Screen > 0 THEN
  396.       BEGIN
  397.          Saved_Screen_List[ Current_Saved_Screen ] := NIL;
  398.          Current_Saved_Screen                      := Current_Saved_Screen - 1;
  399.       END;
  400.  
  401.    FREEMEM( Saved_Screen_Pointer , Saved_Screen_Pointer^.Screen_Size + L );
  402.  
  403.    Saved_Screen_Pointer := NIL;
  404.                                    (* Update status line *)
  405.    Current_Status_Time := -1;
  406.  
  407.    IF Do_Status_Time THEN
  408.       Update_Status_Line;
  409.  
  410. END    (* Restore_Screen *);
  411.  
  412. (*----------------------------------------------------------------------*)
  413. (*                Save_Screen --- Save current screen image             *)
  414. (*----------------------------------------------------------------------*)
  415.  
  416. PROCEDURE Save_Screen( VAR Saved_Screen_Pointer : Saved_Screen_Ptr );
  417.  
  418. (*----------------------------------------------------------------------*)
  419. (*                                                                      *)
  420. (*     Procedure:  Save_Screen                                          *)
  421. (*                                                                      *)
  422. (*     Purpose:    Saves entire current screen image                    *)
  423. (*                                                                      *)
  424. (*     Calling Sequence:                                                *)
  425. (*                                                                      *)
  426. (*        Save_Screen( VAR Saved_Screen_Pointer : Saved_Screen_Ptr );   *)
  427. (*                                                                      *)
  428. (*           Saved_Screen_Pointer  --- pointer to record receiving      *)
  429. (*                                     screen image, window location,   *)
  430. (*                                     and current cursor location.     *)
  431. (*                                                                      *)
  432. (*     Calls:   Save_Partial_Screen                                     *)
  433. (*                                                                      *)
  434. (*----------------------------------------------------------------------*)
  435.  
  436. VAR
  437.    Max_Save_Line : INTEGER;
  438.  
  439. BEGIN (* Save_Screen *)
  440.  
  441.    Max_Save_Line := Max_Screen_Line;
  442.  
  443. {----  Fix this later --- we'd like to avoid bogus status line restores.
  444.  
  445.    IF Do_Status_Line THEN
  446.       Max_Save_Line := PRED( Max_Save_Line );
  447.  
  448. -----}
  449.  
  450.    Save_Partial_Screen( Saved_Screen_Pointer, 1, 1, Max_Screen_Col,
  451.                         Max_Save_Line );
  452.  
  453. END   (* Save_Screen *);
  454.